﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Reflection;

namespace OpenWaves.Reflection
{
    public static class MemberInfoExtensions
    {
        public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo memberInfo) where T : Attribute
        {
            Contract.Requires<ArgumentNullException>(memberInfo != null);
            Contract.Ensures(Contract.Result<IEnumerable<T>>() != null);

            return (T[])Attribute.GetCustomAttributes(memberInfo, typeof(T), false);
        }
    }
}